package com.ffws.H08.utils;

import com.ffws.H08.model.po.H08FireData;
import com.google.gson.Gson;
import com.mongodb.client.FindIterable;
import org.bson.Document;

import java.util.ArrayList;
import java.util.List;

import static com.ffws.H08.system.SystemConstant.DOCUMENT_ID;

/**
 * @Author JC
 * @description TODO
 * @Date 2023-10-28 14:04
 * @Version 1.0
 */
public class FunctionUtil {

    public static final Gson gson = new Gson();

    /**
     * 将 MongoDB上的H08数据的Document 转换为 H08FireData的List
     * @param findIterable H08数据的Document的Iterable
     * @return
     */
    public static List<H08FireData> makeMongoH08DocToList(FindIterable<Document> findIterable) {
        List<H08FireData> h08FireDataList = new ArrayList<>();
        for (Document document : findIterable) {
            H08FireData h08FireData = gson.fromJson(document.toJson(), H08FireData.class);
            String id = document.getString(DOCUMENT_ID);
            h08FireData.setId(id);
            h08FireDataList.add(h08FireData);
        }
        return h08FireDataList;
    }

}
